<template>
	<view class="container">
		<view class="container-list" v-for="(item,index) in userList" :key="index" >
			<view style="display: flex;align-items: center;justify-content: flex-end">
				<u-icon name="share-square" size="24" color="#40d4a8" @click="shareModel(item.RecommendationID)"></u-icon>
			</view>
			<u-read-more showHeight="200" toggle>
				<rich-text :nodes="item.RecommendationText" style="white-space: pre-wrap;"></rich-text>
			</u-read-more>
		</view>
		<view class="deepBox" @click="getNewDeep">
			生成
		</view>

		<u-popup 
		  :show="shareDialog" 
		  mode="center" 
		  bgColor="rgba(0,0,0,0.5)" 
		  @close="shareDialog = false" 
		  round="20"
		  closeable
		  closeIconPos="top-right"
		>
		  <view class="dialog-box">
		    <!-- 标题部分 -->
		    <view class="dialog-header">
		      <text class="dialog-title">分享到社区</text>
		      <view class="title-line"></view>
		    </view>
		
		    <!-- 输入框区域 -->
		    <view class="input-section">
		      <text class="input-label">标题</text>
		      <u--input 
		        placeholder="请输入分享标题" 
		        placeholderClass="placeholder-style"
		        border="bottom"
		        borderColor="#e4e7ed"
		        focusBorderColor="#40d4a8"
		        v-model="shareObj.CommunityTitle"
		        class="custom-input"
		      ></u--input>
		    </view>
		
		    <!-- 操作按钮 -->
		    <view class="action-buttons">
		      <u-button 
		        shape="circle"
		        plain
		        hairline
		        text="取消" 
		        size="medium" 
		        customStyle="width:200rpx;margin-right:30rpx;border-color:#40d4a8;color:#40d4a8"
		        @click="shareDialog = false"
		      ></u-button>
		      <u-button 
		        type="primary" 
		        shape="circle"
		        text="确认分享" 
		        size="medium" 
		        color="#40d4a8"
		        customStyle="width:200rpx"
		        @click="submit"
		      ></u-button>
		    </view>
		  </view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				modelForm: {
					EvaluationID: '',
					mode: 'connection'
				},
				userList: [],
				shareDialog: false,
				shareObj:{
					RecommendationID:'',
					CommunityTitle:''
				}
			};
		},
		onLoad(option) {
			this.id = option.id
			this.getDeepSeekData(option.id)
		},
		methods: {
			async getDeepSeekData(id) {
				const {
					data
				} = await uni.$http.get('/health_suggestion_by_EvaluationID', {
					EvaluationID: id
				})
				if (data.code === 200) {
					this.userList = data.records
				}
			},
			async getNewDeep() {
				this.modelForm.EvaluationID = this.id
				const {
					data
				} = await uni.$http.get('/health_suggestion', this.modelForm)
				if (data.code === 200) {
					this.getDeepSeekData(this.id)
				}
			},
			//分享
			shareModel(id) {
				this.shareDialog = true
				this.shareObj.RecommendationID = id
			},
			async submit(){
				if(this.shareObj.CommunityTitle === ''){
					return this.$refs.uToast.show({
						message: '请输入标题！',
						type: 'error'
					});
				}
				const { data } = await uni.$http.put('/sharing_in_community', this.shareObj)
				if (data.code === 200) {
					this.shareDialog = false
					this.shareObj = {}
					this.$refs.uToast.show({
						message: '提交成功！',
						type: 'success',
						complete() {
							uni.navigateBack();
						}
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 20rpx;
		height: 100vh;
		overflow: auto;
		box-sizing: border-box;
		background-color: #f8f8f8;

		.deepBox {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			background-color: #40d4a8;
			color: #fff;
			font-size: 24rpx;
			position: fixed;
			top: 200rpx;
			right: 50rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.dialog-box {
		  width: 600rpx;
		  padding: 40rpx 50rpx;
		  background: #ffffff;
		  border-radius: 24rpx;
		  box-shadow: 0 20rpx 40rpx rgba(64, 212, 168, 0.15);
		  
		  .dialog-header {
		    margin-bottom: 40rpx;
		    text-align: center;
		    
		    .dialog-title {
		      font-size: 36rpx;
		      font-weight: 600;
		      color: #333;
		      position: relative;
		      display: inline-block;
		      
		      &::after {
		        content: '';
		        position: absolute;
		        left: 50%;
		        bottom: -12rpx;
		        transform: translateX(-50%);
		        width: 60rpx;
		        height: 6rpx;
		        background: #40d4a8;
		        border-radius: 3rpx;
		      }
		    }
		  }
		
		  .input-section {
		    margin-bottom: 50rpx;
		    
		    .input-label {
		      display: block;
		      font-size: 28rpx;
		      color: #666;
		      margin-bottom: 20rpx;
		    }
		
		    .custom-input {
		      padding: 20rpx 0;
		      font-size: 32rpx;
		    }
		
		    .placeholder-style {
		      color: #c0c4cc;
		    }
		  }
		
		  .action-buttons {
		    display: flex;
		    justify-content: center;
		    margin-top: 30rpx;
		  }
		}

		.container-list {
			width: 100%;
			background-color: #fff;
			border-radius: 12rpx;
			padding: 20rpx;
			box-sizing: border-box;
			margin-bottom: 30rpx;
			box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
			color: #999;

			view {
				margin-bottom: 10rpx;
				box-sizing: border-box;
			}
		}
	}
</style>